#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  char *addr;
  int fd;
  struct stat sb;

  if (argc != 2 || strcmp(argv[1],"--help") ==0)
    printf("Wrong usage\n");
  fd = open(argv[1], O_RDONLY);
  if (fd == -1)
    printf("Failed to open %s\n",argv[1]);
  if (fstat(fd, &sb) == -1)
    printf("Failed to stat %s\n",argv[1]);
  addr = (char*)mmap(NULL,sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
  if (addr == MAP_FAILED)
    printf("Failed to open memory mapped file\n");
  if (write(STDOUT_FILENO, addr, sb.st_size) != sb.st_size)
    printf("Only write partially\n");
  exit(EXIT_SUCCESS);
}
